#import "CQChatTableCell.h"

@implementation CQChatTableCell
- (id) init {
	if( ! ( self = [super init] ) )
		return nil;

	_firstChatLine = [[UILabel alloc] init];
	_secondChatLine = [[UILabel alloc] init];

	[self addSubview:_firstChatLine];
	[self addSubview:_secondChatLine];

	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	float grayComponents[4] = { 0.6, 0.6, 0.6, 1. };
	float whiteComponents[4] = { 1., 1., 1., 1. };
	float transparentWhiteComponents[4] = { 1., 1., 1., 0. };

	[_firstChatLine setColor:CGColorCreate(colorSpace, grayComponents)];
	[_secondChatLine setColor:CGColorCreate(colorSpace, grayComponents)];

	[_firstChatLine setHighlightedColor:CGColorCreate(colorSpace, whiteComponents)];
	[_secondChatLine setHighlightedColor:CGColorCreate(colorSpace, whiteComponents)];

	[_firstChatLine setBackgroundColor:CGColorCreate(colorSpace, transparentWhiteComponents)];
	[_secondChatLine setBackgroundColor:CGColorCreate(colorSpace, transparentWhiteComponents)];

	return self;
}

- (void) dealloc {
	[_firstChatLine removeFromSuperview];
	[_secondChatLine removeFromSuperview];

	[_firstChatLine release];
	[_secondChatLine release];
	[_removeConfirmationText release];

	[super dealloc];
}

- (void) layoutSubviews {
	[super layoutSubviews];

	float offset = 0.;

	if( [[_firstChatLine text] length] ) offset -= 10.;
	if( [[_secondChatLine text] length] ) offset -= 10.;

	UILabel *label = [self titleTextLabel];
	CGRect frame = [label frame];
	frame.origin.y += offset;
	[label setFrame:frame];

	frame.origin.y += 20;
	frame.size.width = [self frame].size.width - frame.origin.x - 15.;

	if( [self isRemoveControlVisible] )
		frame.size.width -= [[self removeControl] frame].size.width + 10.;

	[_firstChatLine setFrame:frame];

	frame.origin.y += 20;
	[_secondChatLine setFrame:frame];
}

- (void) updateHighlightColors {
	[super updateHighlightColors];

	UILabel *label = [self titleTextLabel];
	[_firstChatLine setHighlighted:[label isHighlighted]];
	[_secondChatLine setHighlighted:[label isHighlighted]];
}

/*
- (id) createRemoveControl {
	UITableViewCellRemoveControl *control = [super createRemoveControl];
	[control setRemoveConfirmationLabel:( _removeConfirmationText ? _removeConfirmationText: @"Close" )];
	return control;
}
*/

- (void) setRemoveConfirmationText:(NSString *) text {
	[_removeConfirmationText release];
	_removeConfirmationText = [text copy];
}

- (UILabel *) firstChatLineTextLabel {
	return _firstChatLine;
}

- (UILabel *) secondChatLineTextLabel {
	return _secondChatLine;
}

- (void) setFirstChatLineText:(NSString *) text {
	[_firstChatLine setText:text];
	[self layoutSubviews];
}

- (NSString *) firstChatLineText {
	return [_firstChatLine text];
}

- (void) setSecondChatLineText:(NSString *) text {
	[_secondChatLine setText:text];
	[self layoutSubviews];
}

- (NSString *) secondChatLineText {
	return [_secondChatLine text];
}
@end
